﻿namespace WMS6.BLL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.IDAL;
    using WMS6.QueryEntity;
    using WMS6.DALFactory;

    public class LotAttributeBLL
    {
        private static readonly ICommonMethodDA commonMethod = DataAccess.CreateCommonMethod();
        private List<string> dataBaseID;
        private static readonly ILotAttributeDA lotAttributeDA = DataAccess.CreateLotAttributeDA();
        private PubParasInfo pubParasInfo;

        public LotAttributeBLL()
        {
            this.pubParasInfo = null;
        }

        public LotAttributeBLL(string currentWH)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(currentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(currentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001");
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002");
            }
        }

        public LotAttributeBLL(PubParasInfo tempPubParasInfo)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(tempPubParasInfo.CurrentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(tempPubParasInfo.CurrentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001", this.pubParasInfo.UserLanguage);
                }
                else
                {
                    this.pubParasInfo = new PubParasInfo();
                    this.pubParasInfo = tempPubParasInfo;
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002", this.pubParasInfo.UserLanguage);
            }
        }

        public LotAttributeInfo GetLotAttributeInfoByID(string lotAttributeID)
        {
            return lotAttributeDA.GetLotAttributeByID(lotAttributeID, this.dataBaseID[0]);
        }

        public DataSet GetLotAttributeInfoByQueryEntity(LotAttributeQueryEntity lotAttributeQuery)
        {
            List<string> sqlWhere = new List<string>();
            if (!string.IsNullOrEmpty(lotAttributeQuery.OwnerID))
            {
                sqlWhere.Add(" L.OWNER_ID " + lotAttributeQuery.OwnerID);
            }
            if (!string.IsNullOrEmpty(lotAttributeQuery.SkuID))
            {
                sqlWhere.Add(" L.SKU_ID " + lotAttributeQuery.SkuID);
            }
            if (!string.IsNullOrEmpty(lotAttributeQuery.Lot))
            {
                sqlWhere.Add(" L.LOT " + lotAttributeQuery.Lot);
            }
            if (!string.IsNullOrEmpty(lotAttributeQuery.ExternalLot))
            {
                sqlWhere.Add(" L.EXTERNAL_LOT " + lotAttributeQuery.ExternalLot);
            }
            if (!string.IsNullOrEmpty(lotAttributeQuery.VendorID))
            {
                sqlWhere.Add(" L.VENDOR_ID " + lotAttributeQuery.VendorID);
            }
            if (!string.IsNullOrEmpty(lotAttributeQuery.ProduceDate))
            {
                sqlWhere.Add(lotAttributeQuery.ProduceDate.Replace("@ProductDate@", " L.PRODUCE_DATE "));
            }
            if (!string.IsNullOrEmpty(lotAttributeQuery.ExpiryDate))
            {
                sqlWhere.Add(lotAttributeQuery.ExpiryDate.Replace("@ExpiryDate@", " L.EXPIRY_DATE "));
            }
            if (!string.IsNullOrEmpty(lotAttributeQuery.ReceiptDate))
            {
                sqlWhere.Add(lotAttributeQuery.ReceiptDate.Replace("@ReceiptDate@", " L.RECEIPT_DATE "));
            }
            if (!string.IsNullOrEmpty(lotAttributeQuery.LotAttr01))
            {
                sqlWhere.Add(" L.LOT_ATTR01 " + lotAttributeQuery.LotAttr01);
            }
            if (!string.IsNullOrEmpty(lotAttributeQuery.LotAttr02))
            {
                sqlWhere.Add(" L.LOT_ATTR02 " + lotAttributeQuery.LotAttr02);
            }
            if (!string.IsNullOrEmpty(lotAttributeQuery.LotAttr03))
            {
                sqlWhere.Add(" L.LOT_ATTR03 " + lotAttributeQuery.LotAttr03);
            }
            if (!string.IsNullOrEmpty(lotAttributeQuery.LotAttr04))
            {
                sqlWhere.Add(" L.LOT_ATTR04 " + lotAttributeQuery.LotAttr04);
            }
            if (!string.IsNullOrEmpty(lotAttributeQuery.LotAttr05))
            {
                sqlWhere.Add(" L.LOT_ATTR05 " + lotAttributeQuery.LotAttr05);
            }
            if (!string.IsNullOrEmpty(lotAttributeQuery.LotAttr06))
            {
                sqlWhere.Add(" L.LOT_ATTR06 " + lotAttributeQuery.LotAttr06);
            }
            if (!string.IsNullOrEmpty(lotAttributeQuery.LotAttr07))
            {
                sqlWhere.Add(" L.LOT_ATTR07 " + lotAttributeQuery.LotAttr07);
            }
            if (!string.IsNullOrEmpty(lotAttributeQuery.LotAttr08))
            {
                sqlWhere.Add(" L.LOT_ATTR08 " + lotAttributeQuery.LotAttr08);
            }
            if (!string.IsNullOrEmpty(lotAttributeQuery.LotAttr09))
            {
                sqlWhere.Add("L.LOT_ATTR09 " + lotAttributeQuery.LotAttr09);
            }
            if (!string.IsNullOrEmpty(lotAttributeQuery.LotAttr10))
            {
                sqlWhere.Add(" L.LOT_ATTR10 " + lotAttributeQuery.LotAttr10);
            }
            return lotAttributeDA.GetLotAttributeByQueryList(sqlWhere, lotAttributeQuery, this.dataBaseID[0]);
        }
    }
}

